package com.ccbooks.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import cc.software.books.format.Plugin;
import cc.software.books.format.PluginChm;

import com.ccbooks.view.BookContentView;

import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class ContentUtilZero implements Runnable{

	public String fileName;
	public String fontName;
	public int width;
	public String charSet;
	public int percent;
	public int lineNo;
	public int lineCount;
	public short firstThread;
	
	public BooksEngine engine;
	BookContentView bcv;
	private TextView tv;
	public int what;	//决定是在哪一个textview显示；
	
	public ContentUtilZero(BookContentView bcv,String fileName, String fontName, int width,
			String charSet,BooksEngine engine) {
		super();
		this.bcv = bcv;
		this.fileName = fileName;
		this.fontName = fontName;
		this.width = width;
		this.charSet = charSet;
		this.engine = engine;
		
	}
	
	public void setLine(int lineNo,int lineCount){
		this.lineNo = lineNo;
		this.lineCount = lineCount;
	}
	
	public void firstThread(){	
		System.out.println("--------firstThread------------");
		try {
			
		//engine.engineInit(fileName, fontName, width, charSet,TextSizeUtil.fontSize);
			//此方法用于读行；
			//engine.parseFile();
			//content = engine.getPageContent(lineNo, lineCount);
			//此方法用来读取百分比
			
			engine.parseFileZero(fileName, TextSizeUtil.getLineCount(TextSizeUtil.fontSize, bcv.portraint));
			
			
			System.out.println("------end--firstThread------------");
/*			if (true){}
			cc.software.book　s.format.PluginPdb plugin = new cc.software.books.format.PluginPdb();
	    	plugin.open("/sdcard/youduoshaoaikeyiconglai.pdb");
	    	String str= plugin.getData();
	    	Log.d("vrix","pdb text: "+str);
	    	plugin.close();
	    	BooksEngine.content = str;*/
			
			/*PluginChm plugin =  new PluginChm();
	        Log.d("vrix","new Plugin 2");
	        int i = plugin.open("/sdcard/php_manual_en.chm");
	        Log.d("vrix",Integer.toString(i));
	        String str="";
	        str = plugin.getIndex();
	        str = plugin.getData(str);
	        Log.d("vrix","index file1:"+str);
	        str = plugin.html2Txt(str);
	        Log.d("vrix","index file2:"+str);
	        plugin.close();
	        BooksEngine.content = str;*/
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String secThread(){
		try {
			Thread th = new Thread();
			th.sleep(1000);
			engine.getFirstPageContent(lineNo, lineCount);
			
		} catch (IndexOutOfBoundsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return BooksEngine.content;
	}
	
	public void nextPage(){
		
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
	
			firstThread();
		
		
	}
}
